package com.ryl.yomall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ryl.yomall.model.common.result.Result;
import com.ryl.yomall.model.product.*;
import com.ryl.yomall.product.service.ManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date 14:55
 * @Author ryl
 */

@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("admin/product")
public class BaseManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 查询所有的一级分类信息
     * @return
     */
    @GetMapping("getCategory1")
    public Result<List<BaseCategory1>> getCategory1() {
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    /**
     * 根据一级分类Id 查询二级分类数据
     * @param category1Id
     * @return
     */
    @GetMapping("getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id) {
        List<BaseCategory2> baseCategory2List = manageService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    /**
     * 根据二级分类Id 查询三级分类数据
     * @param category2Id
     * @return
     */
    @GetMapping("getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> baseCategory3List = manageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    /**
     * 根据分类Id 获取平台属性数据
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
                                                   @PathVariable("category2Id") Long category2Id,
                                                   @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> baseAttrInfoList = manageService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(baseAttrInfoList);
    }
    /**
     * 根据attrId 查询平台属性对象
     * @param attrId
     * @return
     */
    @GetMapping("getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId) {
        BaseAttrInfo baseAttrInfo = manageService.getAttrInfo(attrId);
        List<BaseAttrValue> baseAttrValueList = baseAttrInfo.getAttrValueList();
        return Result.ok(baseAttrValueList);
    }
    /**
     * 删除平台属性值
     */
    @DeleteMapping("deleteAttrValue/{attrValueName}")
    public Result deleteAttrValue(@PathVariable String attrValueName){

        manageService.deleteAttrValue(attrValueName);
        return Result.ok();
    }
    /**
     * Description: 保存平台属性及属性值
     * @param: baseAttrInfo
     * @return:
     */
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    @DeleteMapping("deleteAttrInfo/{attrId}")
    public Result deleteAttrInfo(@PathVariable String attrId){

        manageService.deleteAttrInfo(attrId);
        return Result.ok();
    }
    /**
     * 查询品牌分页列表
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Integer page ,@PathVariable Integer limit){
      IPage<BaseTrademark> baseTrademarkIPage=manageService.baseTrademark(page,limit);
      return Result.ok ( baseTrademarkIPage );
    }
    /**
     * 去修改品牌
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable Long id){
        BaseTrademark baseTrademark = manageService.getBaseTrademark(id);
        return Result.ok(baseTrademark);
    }

    /**
     * 提交修改品牌
     */
    @PutMapping("/baseTrademark/update")
    public Result baseTrademarkUpdate(@RequestBody BaseTrademark trademark){
        manageService.baseTrademarkUpdate(trademark);
        return Result.ok();
    }
    /**
     * 提交修改品牌
     */
    @PostMapping("/baseTrademark/save")
    public Result baseTrademarkAdd(@RequestBody BaseTrademark trademark){
        manageService.baseTrademarkAdd(trademark);
        return Result.ok();
    }

    /**
     * 提交修改品牌
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result baseTrademarkAdd(@PathVariable Long id){
        manageService.baseTrademarkDelete(id);
        return Result.ok();
    }
    /**
     * 商品分页列表
     */
    @GetMapping("/{page}/{limit}")
    public Result spuList(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            Long category3Id
    ){
        IPage<SpuInfo> spuInfoIPage = manageService.spuList(page,limit,category3Id);
        return Result.ok(spuInfoIPage);
    }

    /**
     * 查询所有品牌
     */
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
       List<BaseTrademark> baseTrademarkList = manageService.getTrademarkList();
       return Result.ok ( baseTrademarkList );
    }
   /**
    *  查询销售属性字典表
    */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList=manageService.baseSaleAttrList();
        return Result.ok ( baseSaleAttrList );
    }
    /**
     * 添加SPU
     */
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }
    /**
     * 根据商品ID查询所有图片
     */
    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId){
        List<SpuImage> spuImageList =  manageService.spuImageList(spuId);
        return Result.ok(spuImageList);
    }
    /**
     * 根据商品ID查询 销售属性及属性值集合
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable Long spuId){
        List<SpuSaleAttr> spuSaleAttrList = manageService.spuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }
    /**
     * 保存SKU
     */
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){

        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    /**
     * 查询SKU分页列表
     */
    @GetMapping({"/list/{page}/{limit}"})
    public Result list(@PathVariable Integer page ,@PathVariable Integer limit){
        IPage<SkuInfo> skuInfoIPage=manageService.list(page,limit);
        return Result.ok ( skuInfoIPage );

    }
    /**
     * 上架
     */
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        manageService.onSale(skuId);
        return Result.ok (  );
    }
    /**
     * 下架
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId)
    {
        manageService.cancelSale(skuId);
        return Result.ok (  );
    }

}
